package demo;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
//链表的阻塞队列
public class Test11 {
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>();
        Thread producer = new Thread(()->{
            int n = 0;
            while (true){
                n++;
                try {
                    //存入
                    blockingDeque.put(n);
                    System.out.println("生产了"+n);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread consumer = new Thread(()->{
            while (true){
                try {
                    //取出
                    Integer n = blockingDeque.take();
                    System.out.println("消费了"+n);

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        producer.start();
        consumer.start();


    }
}
